package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.union.cross.CrossUnionReward;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.date.DateHelper;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_UNION_UPLOAD_REWARD_FROM_CROSS, desc = "商帮获得奖励")
public class UnionUploadRewardCmdFromCross implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {


        CrossUnionProto.CrossUnionUploadRewardRespMsg respMsg = CrossUnionProto.CrossUnionUploadRewardRespMsg.parseFrom(packet.getBytes());
        int now = DateHelper.getCurrentSecond();
        for (long recordId : respMsg.getRecordIdList()) {
            CrossUnionReward reward = CrossUnionMgr.getUnionRewardMap().get(recordId);
            if(reward != null){
                reward.setSync(1);
                reward.setSyncTime(now);
            }
        }

    }
}
